import {Graph} from '@antv/x6'
import Delete from '@/assets/tools/delete.png'

Graph.registerNodeTool('delete-item', {
  inherit:'button', // 基类名称，使用已经注册的工具名称。
  markup: [
    {
      tagName: 'rect',
      selector: 'body',
      attrs: {
        fill: 'white',
        width: 30,
        height: 30,
      }
    },
    {
      tagName: 'image',
      selector: 'icon',
      attrs: {
        width: 25,
        height: 25,
        'xlink:href': Delete,
        x: 2,
        y: 2,
      },
    },
  ],
  x: 68,
  y: 10,
  onClick (e) {
    ElMessageBox.confirm('确定删除?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      e.view.graph.removeCell(e.cell)
      ElMessage({
        type: 'success',
        message: '删除成功!'
      });
    }).catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消删除'
      });
    });
  },
})


Graph.registerEdgeTool('delete-item', {
  inherit:'button', // 基类名称，使用已经注册的工具名称。
  markup: [
    {
      tagName: 'rect',
      selector: 'body',
      attrs: {
        fill: 'transparent',
        width: 30,
        height: 30,
      }
    },
    {
      tagName: 'image',
      selector: 'icon',
      attrs: {
        width: 25,
        height: 25,
        'xlink:href': Delete,
        x: 2,
        y: 2,
      },
    },
  ],
  x: 65,
  y: 10,
  onClick (e) {
    ElMessageBox.confirm('确定删除?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      e.view.graph.removeCell(e.cell)
      ElMessage({
        type: 'success',
        message: '删除成功!'
      });
    }).catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消删除'
      });
    });
  },
})
